/*

    This file is part of Blue Violin.

    Blue Violin is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Blue Violin is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero Public License for more details.

    You should have received a copy of the GNU Affero Public License
    along with Blue Violin.  If not, see <http://www.gnu.org/licenses/>.

    Blue Violin  Copyright (C) 2008  Blue Violin, Inc. & Josh Watts <josh.watts@blueviolin.org>
	For more information, visit http://www.blueviolin.org/

    This program comes with ABSOLUTELY NO WARRANTY.

*/

function BVPopupTabs()
{
	this.m_sPreviousColor = null;
	this.m_oPrevious = $get("spnMainBrowser");
	
	$get("spnMainBrowser").attachEvent("onmouseover",
									   $createDelegate(this, this.mouseOver));
	$get("spnMainBrowser").attachEvent("onmouseout",
									   $createDelegate(this, this.mouseOut));
	$get("spnMainBrowser").attachEvent("onclick",
									   $createDelegate(this, this.select));
	
}


BVPopupTabs.prototype.addTab = function(sTabName)
{
	var spnTab = $create("SPAN");
	var spnInner = $create("SPAN");
	var imgClose = $create("IMG");

	spnTab.id = "spn" + sTabName.replace(/\s+/g, "");
	spnTab.className = "PopupTabsSpan";

	spnInner.innerHTML = sTabName;
	spnInner.id = "spnInner";
	
	imgClose.src = "./images/toolbar/close_red_12_normal.gif";
	imgClose.style.height = "12px";
	imgClose.style.width = "12px";
	imgClose.id = "imgCloseSpn" + sTabName;
	imgClose.className = "PopupTabClose";
	imgClose.attachEvent("onclick",
						 $createDelegate(this, this.closeTab));

	spnTab.appendChild(imgClose);
	spnTab.appendChild(spnInner);
	
	$get("divPopupTabs").appendChild(spnTab);

	spnTab.attachEvent("onmouseover",
						 $createDelegate(this, this.mouseOver));
	spnTab.attachEvent("onmouseout",
					   $createDelegate(this, this.mouseOut));
	spnTab.attachEvent("onclick",
					   $createDelegate(this, this.select));

	this.m_oPrevious.style.color = "black";
	spnTab.style.color = "white";
	this.m_oPrevious = spnTab;

	return spnTab;

};


BVPopupTabs.prototype.mouseOver = function()
{
// 	var oElement = this.getTab(window.event.srcElement);
	
// 	this.m_sPreviousColor = oElement.style.color;
	
// 	oElement.style.color = "#777777";
};


BVPopupTabs.prototype.mouseOut = function()
{
// 	var oElement = this.getTab(window.event.srcElement);
	
// 	if (null != this.m_sPreviousColor)
// 	{
// 		oElement.style.color = this.m_nPreviousColor;
// 	}
// 	else
// 	{
// 		oElement.style.color = "#000000";
// 	}
	
	
};


BVPopupTabs.prototype.select = function()
{
	var oElement = this.getTab(window.event.srcElement);

	window.oPopupScripts[oElement.id.replace("spn", "obj")].SwitchActiveBrowser(oElement);
	if (null != this.m_oPrevious)
	{
		this.m_oPrevious.style.color = "black";
	}

	oElement.style.color = "white";
	this.m_oPrevious = oElement;
	
};


BVPopupTabs.prototype.getTab = function(oElement)
{
	if ("spnInner" == oElement.id)
	{
		return oElement.parentNode;
	}
	else
	{
		return oElement;
	}
};
	
	
BVPopupTabs.prototype.closeTab = function()
{
	var sAction = "closewindow";
	var oAttributes = {};

	oAttributes.browserID = window.event.srcElement.parentNode.id.replace("spn", "obj");
	window.oAppEvents.AddAction(sAction, oAttributes);
	window.oAppEvents.CloseWindow(window.event.srcElement.parentNode.id.replace("spn", "obj"));

	this.m_oPrevious.style.color = "black";
	$get("spnMainBrowser").style.color = "white";

	this.m_oPrevious = $get("spnMainBrowser");
};


BVPopupTabs.prototype.reset = function()
{
	$get("spnMainBrowser").style.color = "white";
	this.m_oPrevious = $get("spnMainBrowser");
};
